import 'reflect-metadata';
class myClass {
    private property:string;
    constructor(value:string){
        this.property = value;
    }
    @Reflect.metadata('customKey','customKey-value')
    getProperty(){
        console.log(this.property,Reflect.getMetadata('customKey',this,'getProperty'))
    }
}
const instance = new myClass('hello reflect-metadata');
instance.getProperty()

// 给instance上的property定义一个元数据，属性是key1，值是value1
Reflect.defineMetadata('key1','value1',instance,'property')
// 检查是否具有指定元数据
const hasMetdata = Reflect.hasMetadata('key1',instance,'property');
console.log('instance实例上property是否有key1这个元数据:'+hasMetdata);
// 获取实例元数据
const metaDataValue = Reflect.getMetadata('key1',instance,'property');
console.log(metaDataValue);

// @Reflect.metadata('customKey','customKey-value') 其实是一个语法糖，可以简化对元数据的操作
// Reflect.defineMetadata('customKey','customkey value',myClass.prototype,'getProperty');

// 获取自有元数据(针对方法)
const ownMetaDataValue = Reflect.getOwnMetadata('customKey',myClass.prototype,'getProperty');
console.log('instance实例getProperty方法的元数据 customKey: '+ownMetaDataValue);

const ownMetaDataValue3 = Reflect.getOwnMetadata('customKey',Reflect.getPrototypeOf(instance),'getProperty');
console.log('instance实例getProperty方法的元数据 customKey: '+ownMetaDataValue3);

const ownMetaDataValue2 = Reflect.getMetadata('customKey',instance,'getProperty');
console.log('instance实例getProperty方法的元数据 customKey: '+ownMetaDataValue2);

// 删除元数据
Reflect.deleteMetadata('key1',instance,'property');
// 验证删除
const hasMetdata2 = Reflect.hasMetadata('key1',instance,'property');
console.log('instance实例上property是否有key1这个元数据:'+hasMetdata2);